const {http, handleStr} = require("../../utils/utils")

Page({
  data: {
    albums:[]
  },
  
  onLoad() {
   var url=`http://47.108.197.28:3000/top/album`
   http({
     url,
     success:res=>{
      // console.log(res.data.albums)
      this.handleHttpData(res)
     }
   })
  },
  handleHttpData(res){
    var albums=[]
    var album=res.data.albums;
    album.forEach(item=>{
      // console.log(item.id)
      var {picUrl,name,id,artist}=item;
      var songer=artist.name;
      // console.log(songer)
      albums.push({
        picUrl,
        name:handleStr(name),
        id,
        songer
      })
    })
    this.setData({albums})
  },
  handleItem(event){ 
    console.log(event.currentTarget.dataset)
   var {aid}=event.currentTarget.dataset;
   wx.navigateTo({
     url: `/pages/detail/detail?id=${aid}`,
   });
  }

  
})
